import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';
import { GitManagerService } from '@common/services/git/gitmanager';
import {DockerTask, GitPipelinetask} from "@api/git";

@Component({
  selector: 'kd-dockerimages',
  templateUrl: './dockerimages.component.html',
  styleUrls: ['./dockerimages.component.scss']
})
export class DockerImagesComponent implements OnInit {

  selected_HASH  = 'UNKNOW';
  selected =  'option2';
  _tasks :GitPipelinetask[] = [];
  _docker_builder : DockerTask[] = [];
  log_hash :string  = "";
  log_module:string = "";
  select_i:number = 0;
  constructor( private readonly gits :GitManagerService,
    private readonly _ref :ChangeDetectorRef ) { }
  @Input('tasks')
  set tasks(tasks:GitPipelinetask[]){
      this._tasks = tasks
  }
  hello(){
    console.log(this.selected)
    this.gits.DockerTasksByGitHash(this.selected).subscribe(
      data => {
        this._docker_builder = data
        this._ref.markForCheck()
        //this._ref.detectChanges()
      }
    )

  }
  ngOnInit(): void {
    console.log(this._tasks)
  }
  ChangeLogfile( i :number){
    this.select_i = i
    this.log_hash = this._docker_builder[i].GitHash.substring(0,8)
    this.log_module = this._docker_builder[i].project_name
    this._ref.markForCheck()
  }
  GetButtonColor(i :number ):string{
    if (i==this.select_i) return "warn";
    else return "accent";
  }

}
